import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import { router } from 'dva';
import moment from "moment";
const { Link } = router;

export default (self) => [
  {
    title: 'ID',
    name: 'id',
    // tableItem: {},

    formItem: {
      type: 'hidden',
    }
  },
  {
    title: '用户名',
    name: 'realname',
    searchItem: {
      group: 'abc',
      name: 'name',
    },
    tableItem: {},
    formItem: {
      rules: [
        {required: true, message: '请填写用户名'},
        {validator: (rule, value, callback)=>{
            if (!value || !(/^[\u4e00-\u9fa5]+$/.test(value))){
              callback('请填写正确的姓名(仅可使用汉字)');
            }else{
              callback();
            }
          }}
      ],},
  },
  {
    title: '昵称',
    name: 'nickname',
    tableItem: {},
    formItem: {},
  },
  {
    title: '手机号',
    name: 'mobile',
    tableItem: {},
    formItem: {rules: [
        {required: true, message: '请填写手机号'},
        {
          validator: (rule, value, callback)=>{
            if (!value || !(/^1[3456789]\d{9}$/.test(value))){
              callback('请填写正确的手机号');
            }else{
              callback();
            }
          }
        }
      ]},
  },
  {
    title: '密码',
    name: 'password',
    formItem: {
      type: 'password',
      repeat: true,
      rulesForAdd: [],
    }
  },
  {
    title: '状态',
    name: 'isActive',
    dict: [{ code: 0, codeName: '停用' }, { code: 1, codeName: '正常' }],
    tableItem: { render: t => t?  '正常' :'停用'},
  },

  // {
  //   title: '备注',
  //   name: 'description',
  //   tableItem: {},
  //   formItem: {}
  // },
  {
    title: '创建时间',
    name: 'createTime',
    tableItem: {
      render: text =>
        moment.utc(text).format('YYYY-MM-DD HH:mm')
      // moment.utc(text).toDate().toLocaleDateString()
    },
  },
  {
    title: '操作',
    tableItem: {
      width: 180,
      render: (text, record) => {
        let activeBtn;
        if (record.isActive)
          activeBtn = <Button tooltip="停用" onClick={e =>self.handleActive(record, 0)}><Icon type="StopOutlined" antd></Icon> </Button>;
        else
          activeBtn = <Button tooltip="启用" onClick={e =>self.handleActive(record, 1)}><Icon type="CheckCircleOutlined" antd></Icon> </Button>;
        return <DataTable.Oper>
          <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
            <Icon type="edit" />
          </Button>
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash" />
          </Button>
          <Button tooltip="角色" onClick={e => self.showRoleForm(record)}>
            <Icon type="users" />
          </Button>
          {activeBtn}
        </DataTable.Oper>
      }
    }
  }
];
